import org.hibernate.FetchMode

class UserService {

    def authenticateService

    boolean transactional = false

    def fetchFullAuthUser(id) {
        def c = AuthUser.createCriteria()
        def results = c{
            eq('id', id)
            fetchMode('', FetchMode.JOIN)
        }
        return results[0]

    }

    def currentCustomer(){
        def userId = authenticateService.userDomain().id
        def person = fetchFullAuthUser(userId)?.person
        return person?Customer.get(person.id):null

    }

    def currentStaff(){
        def userId = authenticateService.userDomain().id
        def person = fetchFullAuthUser(userId)?.person
        return person?Staff.get(person.id):null

    }
}
